<template>
	<view>
		<template v-if="landInfoList">
			<landInfo v-for="(items, index) in landInfoList" :key="index" :landInfo="items"></landInfo>
			<loadMore :loadtext="loadtext"></loadMore>
		</template>
		<template v-else>
			<no-land></no-land>
		</template>
	</view>
</template>

<script>
	import landInfo from "../../../components/landInfo/landInfo.vue"
	import loadMore from "../../../components/common/load-more.vue"
	import noLand from '../../../components/common/no-land.vue'
	export default {
		components:{
			landInfo,
			loadMore,
			noLand
		},
		data() {
			return {
				ruser_id:"",
				landInfoList:[],
				loadtext:"上拉加载更多",
				page: 1,
				size: 6,
			}
		},
		onLoad(e) {
			// console.log(e.ruser_id);
			this.ruser_id = e.ruser_id;
			this.getUserCollectInfo();
		},
		
		// 监听下拉刷新事件
		onPullDownRefresh() {
			this.getCollectData();
		},
		
		// 监听上拉触底事件
		onReachBottom(){
			this.loadMore();
		},
		
		methods: {
			async getUserCollectInfo(){
				const res=await this.$http({
					url: "/app/landInfo/selectUserCollectPaging",
					data: {
						city: this.ruser_id,
						page: this.page,
						size: this.size,
					},
				})
				// console.log(res);
				this.landInfoList = res.data.data.list;
			},
			
			// 下拉刷新事件
			getCollectData(){
				this.page = 1;
				this.loadtext = "上拉加载更多";
				setTimeout(()=> {
					this.getUserCollectInfo();
					// 关闭下拉刷新
					uni.stopPullDownRefresh();
				}, 2000);
			},
			
			// 上拉加载更多
			loadMore(){
			    if(this.loadtext != "上拉加载更多"){ return;}
			    this.loadtext = "加载中...";	
			    this.page++;
			    setTimeout(() => {
				uni.request({
					url: this.confige.webUrl + "/app/landInfo/selectUserCollectPaging",
					data:{
						city: this.ruser_id,
						page: this.page,
						size: this.size,
					},
					header:{},
					success: (res) => {
						// console.log(res);
						if(res.data.code === 206 || res.data.data.pages < this.page){
							this.loadtext = "没有更多数据啦";
							return;
						}
						else if(res.data.code === 200){
							let list = res.data.data.list;
							this.landInfoList.push(...list);
							this.loadtext = "上拉加载更多";
						} else {
						 	this.loadtext = "没有更多数据啦";
						}
					}	
				}	  
				)}, 1000);
			},
		}
	}
</script>

<style lang="less" scoped>
	
</style>
